const cmd = require('node-cmd')
import { join, parse } from 'path'

const isDev = process.env.NODE_ENV === 'development'

export default (filepath) =>
  new Promise((resolve, reject) => {
    let basePath = join(__dirname, '../../resources')
    isDev || (basePath = basePath.replace('app.asar', 'app.asar.unpacked'))
    const p = `${basePath}\\extracticon.exe`
    const png = `${basePath}\\${parse(filepath).name}.png`

    const { data } = cmd.runSync(`"${p}" "${filepath}" "${png}"`)
    data.includes('Success') ? resolve(png) : reject(data)
  })
